﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NIP.DynamicControl
{
    public enum GripperStatus
    {
        OPEN = 0,
        CLOSED,
        HOLDING,
        FALSE_VALUE,
    }
    
    public class GripperStatusHelper
    {
       
        public  const int FULLY_OPEN_MM = 74;

        public  const int HOLDING_THRESHOLD_PERCENTAGE = 90; //< percent means holding something
        public  const int CLOSED_THRESHOLD_PERCENTAGE = 10; // < percent assumed to be closed

         public  const int HOLDING_THRESHOLD_MM = (HOLDING_THRESHOLD_PERCENTAGE*74)/100; //< percent means holding something // 74 fully open
        public  const int CLOSED_THRESHOLD_MM = (CLOSED_THRESHOLD_PERCENTAGE*74)/100; // < percent assumed to be closed

        public static GripperStatus TranslateFromJawPercentToGripper(short percent)
        {
            if (percent > HOLDING_THRESHOLD_PERCENTAGE) return GripperStatus.OPEN;
            else if (percent > CLOSED_THRESHOLD_PERCENTAGE) return GripperStatus.HOLDING;
            else return GripperStatus.CLOSED;
        }

        public static GripperStatus TranslateFromJawMMToGripper(short mm)
        {
            if (mm <= FULLY_OPEN_MM)
            {
                if (mm > HOLDING_THRESHOLD_MM) return GripperStatus.OPEN;
                else if (mm > CLOSED_THRESHOLD_MM) return GripperStatus.HOLDING;
                else return GripperStatus.CLOSED;
            }
            else
                return GripperStatus.FALSE_VALUE;
        }

    }

}
